
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 02/26/2011 18:14:07
-- Generated from EDMX file: E:\Develop\FitnessHelper\FitnessHelperDB\FitnessHelperModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [FitnessHelper];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_FoodUnitsFoods]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Foods] DROP CONSTRAINT [FK_FoodUnitsFoods];
GO
IF OBJECT_ID(N'[dbo].[FK_MusclesExercises]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Exercises] DROP CONSTRAINT [FK_MusclesExercises];
GO
IF OBJECT_ID(N'[dbo].[FK_ExercisesWeightRecords]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[WeightRecords] DROP CONSTRAINT [FK_ExercisesWeightRecords];
GO
IF OBJECT_ID(N'[dbo].[FK_ProgrammsProgrammDays]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProgrammDays] DROP CONSTRAINT [FK_ProgrammsProgrammDays];
GO
IF OBJECT_ID(N'[dbo].[FK_ProgrammDaysProgrammExercises]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProgrammExercises] DROP CONSTRAINT [FK_ProgrammDaysProgrammExercises];
GO
IF OBJECT_ID(N'[dbo].[FK_ExercisesProgrammExercises]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProgrammExercises] DROP CONSTRAINT [FK_ExercisesProgrammExercises];
GO
IF OBJECT_ID(N'[dbo].[FK_ProgrammDaysCalendarRecords]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CalendarRecords] DROP CONSTRAINT [FK_ProgrammDaysCalendarRecords];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FoodUnits]', 'U') IS NOT NULL
    DROP TABLE [dbo].[FoodUnits];
GO
IF OBJECT_ID(N'[dbo].[Foods]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Foods];
GO
IF OBJECT_ID(N'[dbo].[Muscles]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Muscles];
GO
IF OBJECT_ID(N'[dbo].[Exercises]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Exercises];
GO
IF OBJECT_ID(N'[dbo].[WeightRecords]', 'U') IS NOT NULL
    DROP TABLE [dbo].[WeightRecords];
GO
IF OBJECT_ID(N'[dbo].[Programms]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Programms];
GO
IF OBJECT_ID(N'[dbo].[ProgrammDays]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProgrammDays];
GO
IF OBJECT_ID(N'[dbo].[ProgrammExercises]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProgrammExercises];
GO
IF OBJECT_ID(N'[dbo].[CalendarRecords]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CalendarRecords];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'FoodUnits'
CREATE TABLE [dbo].[FoodUnits] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Foods'
CREATE TABLE [dbo].[Foods] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Calories] float  NOT NULL,
    [Proteins] float  NOT NULL,
    [Carbohydrates] float  NOT NULL,
    [Fats] float  NOT NULL,
    [FoodUnits_Id] int  NOT NULL
);
GO

-- Creating table 'Muscles'
CREATE TABLE [dbo].[Muscles] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Exercises'
CREATE TABLE [dbo].[Exercises] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Muscles_Id] int  NOT NULL
);
GO

-- Creating table 'WeightRecords'
CREATE TABLE [dbo].[WeightRecords] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Repeats] int  NULL,
    [MaxWeight] float  NOT NULL,
    [MaxRepeats] int  NOT NULL,
    [Exercises_Id] int  NOT NULL
);
GO

-- Creating table 'Programms'
CREATE TABLE [dbo].[Programms] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'ProgrammDays'
CREATE TABLE [dbo].[ProgrammDays] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Index] int  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Programms_Id] int  NOT NULL
);
GO

-- Creating table 'ProgrammExercises'
CREATE TABLE [dbo].[ProgrammExercises] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Index] int  NOT NULL,
    [Sets] int  NOT NULL,
    [Repeats] int  NULL,
    [SuperSetIndex] int  NULL,
    [ProgrammDays_Id] int  NOT NULL,
    [Exercises_Id] int  NOT NULL
);
GO

-- Creating table 'CalendarRecords'
CREATE TABLE [dbo].[CalendarRecords] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Date] datetime  NOT NULL,
    [ProgrammDays_Id] int  NOT NULL
);
GO

-- Creating table 'FoodPortions'
CREATE TABLE [dbo].[FoodPortions] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Amount] float  NOT NULL,
    [Foods_Id] int  NOT NULL,
    [FoodIntakes_Id] int  NOT NULL
);
GO

-- Creating table 'FoodIntakes'
CREATE TABLE [dbo].[FoodIntakes] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Index] int  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [FoodPlanDays_Id] int  NOT NULL
);
GO

-- Creating table 'FoodPlans'
CREATE TABLE [dbo].[FoodPlans] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'FoodPlanDays'
CREATE TABLE [dbo].[FoodPlanDays] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Index] int  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [FoodPlans_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'FoodUnits'
ALTER TABLE [dbo].[FoodUnits]
ADD CONSTRAINT [PK_FoodUnits]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Foods'
ALTER TABLE [dbo].[Foods]
ADD CONSTRAINT [PK_Foods]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Muscles'
ALTER TABLE [dbo].[Muscles]
ADD CONSTRAINT [PK_Muscles]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Exercises'
ALTER TABLE [dbo].[Exercises]
ADD CONSTRAINT [PK_Exercises]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'WeightRecords'
ALTER TABLE [dbo].[WeightRecords]
ADD CONSTRAINT [PK_WeightRecords]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Programms'
ALTER TABLE [dbo].[Programms]
ADD CONSTRAINT [PK_Programms]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ProgrammDays'
ALTER TABLE [dbo].[ProgrammDays]
ADD CONSTRAINT [PK_ProgrammDays]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ProgrammExercises'
ALTER TABLE [dbo].[ProgrammExercises]
ADD CONSTRAINT [PK_ProgrammExercises]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'CalendarRecords'
ALTER TABLE [dbo].[CalendarRecords]
ADD CONSTRAINT [PK_CalendarRecords]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'FoodPortions'
ALTER TABLE [dbo].[FoodPortions]
ADD CONSTRAINT [PK_FoodPortions]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'FoodIntakes'
ALTER TABLE [dbo].[FoodIntakes]
ADD CONSTRAINT [PK_FoodIntakes]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'FoodPlans'
ALTER TABLE [dbo].[FoodPlans]
ADD CONSTRAINT [PK_FoodPlans]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'FoodPlanDays'
ALTER TABLE [dbo].[FoodPlanDays]
ADD CONSTRAINT [PK_FoodPlanDays]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [FoodUnits_Id] in table 'Foods'
ALTER TABLE [dbo].[Foods]
ADD CONSTRAINT [FK_FoodUnitsFoods]
    FOREIGN KEY ([FoodUnits_Id])
    REFERENCES [dbo].[FoodUnits]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_FoodUnitsFoods'
CREATE INDEX [IX_FK_FoodUnitsFoods]
ON [dbo].[Foods]
    ([FoodUnits_Id]);
GO

-- Creating foreign key on [Muscles_Id] in table 'Exercises'
ALTER TABLE [dbo].[Exercises]
ADD CONSTRAINT [FK_MusclesExercises]
    FOREIGN KEY ([Muscles_Id])
    REFERENCES [dbo].[Muscles]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MusclesExercises'
CREATE INDEX [IX_FK_MusclesExercises]
ON [dbo].[Exercises]
    ([Muscles_Id]);
GO

-- Creating foreign key on [Exercises_Id] in table 'WeightRecords'
ALTER TABLE [dbo].[WeightRecords]
ADD CONSTRAINT [FK_ExercisesWeightRecords]
    FOREIGN KEY ([Exercises_Id])
    REFERENCES [dbo].[Exercises]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ExercisesWeightRecords'
CREATE INDEX [IX_FK_ExercisesWeightRecords]
ON [dbo].[WeightRecords]
    ([Exercises_Id]);
GO

-- Creating foreign key on [Programms_Id] in table 'ProgrammDays'
ALTER TABLE [dbo].[ProgrammDays]
ADD CONSTRAINT [FK_ProgrammsProgrammDays]
    FOREIGN KEY ([Programms_Id])
    REFERENCES [dbo].[Programms]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProgrammsProgrammDays'
CREATE INDEX [IX_FK_ProgrammsProgrammDays]
ON [dbo].[ProgrammDays]
    ([Programms_Id]);
GO

-- Creating foreign key on [ProgrammDays_Id] in table 'ProgrammExercises'
ALTER TABLE [dbo].[ProgrammExercises]
ADD CONSTRAINT [FK_ProgrammDaysProgrammExercises]
    FOREIGN KEY ([ProgrammDays_Id])
    REFERENCES [dbo].[ProgrammDays]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProgrammDaysProgrammExercises'
CREATE INDEX [IX_FK_ProgrammDaysProgrammExercises]
ON [dbo].[ProgrammExercises]
    ([ProgrammDays_Id]);
GO

-- Creating foreign key on [Exercises_Id] in table 'ProgrammExercises'
ALTER TABLE [dbo].[ProgrammExercises]
ADD CONSTRAINT [FK_ExercisesProgrammExercises]
    FOREIGN KEY ([Exercises_Id])
    REFERENCES [dbo].[Exercises]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ExercisesProgrammExercises'
CREATE INDEX [IX_FK_ExercisesProgrammExercises]
ON [dbo].[ProgrammExercises]
    ([Exercises_Id]);
GO

-- Creating foreign key on [ProgrammDays_Id] in table 'CalendarRecords'
ALTER TABLE [dbo].[CalendarRecords]
ADD CONSTRAINT [FK_ProgrammDaysCalendarRecords]
    FOREIGN KEY ([ProgrammDays_Id])
    REFERENCES [dbo].[ProgrammDays]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProgrammDaysCalendarRecords'
CREATE INDEX [IX_FK_ProgrammDaysCalendarRecords]
ON [dbo].[CalendarRecords]
    ([ProgrammDays_Id]);
GO

-- Creating foreign key on [Foods_Id] in table 'FoodPortions'
ALTER TABLE [dbo].[FoodPortions]
ADD CONSTRAINT [FK_FoodsFoodPortions]
    FOREIGN KEY ([Foods_Id])
    REFERENCES [dbo].[Foods]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_FoodsFoodPortions'
CREATE INDEX [IX_FK_FoodsFoodPortions]
ON [dbo].[FoodPortions]
    ([Foods_Id]);
GO

-- Creating foreign key on [FoodIntakes_Id] in table 'FoodPortions'
ALTER TABLE [dbo].[FoodPortions]
ADD CONSTRAINT [FK_FoodIntakesFoodPortions]
    FOREIGN KEY ([FoodIntakes_Id])
    REFERENCES [dbo].[FoodIntakes]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_FoodIntakesFoodPortions'
CREATE INDEX [IX_FK_FoodIntakesFoodPortions]
ON [dbo].[FoodPortions]
    ([FoodIntakes_Id]);
GO

-- Creating foreign key on [FoodPlans_Id] in table 'FoodPlanDays'
ALTER TABLE [dbo].[FoodPlanDays]
ADD CONSTRAINT [FK_FoodPlansFoodPlanDays]
    FOREIGN KEY ([FoodPlans_Id])
    REFERENCES [dbo].[FoodPlans]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_FoodPlansFoodPlanDays'
CREATE INDEX [IX_FK_FoodPlansFoodPlanDays]
ON [dbo].[FoodPlanDays]
    ([FoodPlans_Id]);
GO

-- Creating foreign key on [FoodPlanDays_Id] in table 'FoodIntakes'
ALTER TABLE [dbo].[FoodIntakes]
ADD CONSTRAINT [FK_FoodPlanDaysFoodIntakes]
    FOREIGN KEY ([FoodPlanDays_Id])
    REFERENCES [dbo].[FoodPlanDays]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_FoodPlanDaysFoodIntakes'
CREATE INDEX [IX_FK_FoodPlanDaysFoodIntakes]
ON [dbo].[FoodIntakes]
    ([FoodPlanDays_Id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------